﻿'Imports Microsoft.VisualBasic
'Imports Outlook = Microsoft.Office.Interop.Outlook
Public Class Sample

    'Shared Sub SendEmailFromAccount(ByVal application As Outlook.Application, _
    '    ByVal subject As String, ByVal body As String, ByVal recipients As String, ByVal smtpAddress As String)

    '    ' Create a new MailItem and set the To, Subject, and Body properties.
    '    Dim newMail As Outlook.MailItem = DirectCast(application.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItem)
    '    newMail.To = recipients
    '    newMail.Subject = subject
    '    newMail.Body = body

    '    ' Retrieve the account that has the specific SMTP address.
    '    Dim account As Outlook.Account = GetAccountForEmailAddress(application, smtpAddress)
    '    ' Use this account to send the e-mail.
    '    newMail.SendUsingAccount = account
    '    'newMail.Send()
    'End Sub

    'Shared Function GetAccountForEmailAddress(ByVal application As Outlook.Application, ByVal smtpAddress As String) As Outlook.Account
    '    ' Loop over the Accounts collection of the current Outlook session.
    '    Dim accounts As Outlook.Accounts = application.Session.Accounts
    '    Dim account As Outlook.Account
    '    For Each account In accounts
    '        ' When the e-mail address matches, return the account.
    '        If account.SmtpAddress = smtpAddress Then
    '            Return account
    '        End If
    '    Next
    '    Throw New System.Exception(String.Format("No Account with SmtpAddress: {0} exists!", smtpAddress))
    'End Function

End Class
